import type { LineString } from 'geojson'

export function stringifyLineString(ls: LineString): string {
  return stringifyCoordinates(ls.coordinates)
}

export function stringifyCoordinates(coordinates: number[][] | undefined | null): string {
  if (!coordinates || coordinates.length === 0) {
    return ''
  }
  let ret = ''
  for (let i = 0; i < coordinates.length; i++) {
    if (i !== 0) {
      ret += '\n'
    }
    ret += stringifyCoordinate(coordinates[i])
  }
  return ret
}

export function stringifyCoordinate(coord: number[]): string {
  return `${coord[0]},${coord[1]}`
}
